package com.example.tvidemo.service;

import com.example.tvidemo.entity.User;
import com.example.tvidemo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public List<User> findAll(){
        return userMapper.findAll();
    }

    public User findByUserName(String name){
        return userMapper.findByUserName(name);
    }

    public void addUser(User user){
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        user.setId(uuid);
        userMapper.addUser(user);
    }

    public User findByUserId(String id){
        return userMapper.findByUserId(id);
    }

    public void updateUser(User user){
        userMapper.updateUser(user);
    }

    public void deleteUser(String id){
        userMapper.deleteUser(id);
    }
}
